# cmake_minimum_required(VERSION 3.8)
# project(slam_robot)

# # 设置 C++17 标准
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)

# # 查找依赖项
# find_package(ament_cmake REQUIRED)
# find_package(rclcpp REQUIRED)
# find_package(sensor_msgs REQUIRED)
# find_package(nav_msgs REQUIRED)
# find_package(geometry_msgs REQUIRED)
# find_package(tf2 REQUIRED)
# find_package(tf2_ros REQUIRED)

# # 添加包含目录
# include_directories(
#   include
#   ${rclcpp_INCLUDE_DIRS}
#   ${sensor_msgs_INCLUDE_DIRS}
#   ${nav_msgs_INCLUDE_DIRS}
#   ${geometry_msgs_INCLUDE_DIRS}
#   ${tf2_ros_INCLUDE_DIRS}
# )

# # 创建串口桥库
# add_library(serial_bridge SHARED src/serial_bridge.cpp)
# target_link_libraries(serial_bridge
#   ${rclcpp_LIBRARIES}
# )

# # 创建主节点可执行文件
# add_executable(main_node 
#   src/main_node.cpp 
#   src/imu_publisher.cpp 
#   src/odometry_publisher.cpp
# )

# # 链接依赖
# target_link_libraries(main_node
#   serial_bridge
#   ${rclcpp_LIBRARIES}
#   ${sensor_msgs_LIBRARIES}
#   ${nav_msgs_LIBRARIES}
#   ${geometry_msgs_LIBRARIES}
#   ${tf2_ros_LIBRARIES}
#   ${tf2_LIBRARIES}
# )

# # 安装目标（关键修改：RUNTIME_DESTINATION 改为 lib/slam_robot）
# install(TARGETS 
#   main_node 
#   serial_bridge
#   ARCHIVE DESTINATION lib
#   LIBRARY DESTINATION lib
#   RUNTIME DESTINATION lib/${PROJECT_NAME}  # 修改点：从 bin 改为 lib/slam_robot
# )

# install(DIRECTORY 
#   launch 
#   DESTINATION share/${PROJECT_NAME}
# )

# install(DIRECTORY 
#   include/
#   DESTINATION include
# )

# # 添加 ament 导出
# ament_export_include_directories(include)
# ament_export_libraries(serial_bridge)
# ament_package()

cmake_minimum_required(VERSION 3.8)
project(slam_robot)

# 设置 C++17 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找依赖项
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)

# 添加包含目录
include_directories(
  include
  ${rclcpp_INCLUDE_DIRS}
  ${sensor_msgs_INCLUDE_DIRS}
  ${nav_msgs_INCLUDE_DIRS}
  ${geometry_msgs_INCLUDE_DIRS}
  ${tf2_ros_INCLUDE_DIRS}
)

# 创建串口桥库（不再依赖wiringPi）
add_library(serial_bridge SHARED 
  src/serial_bridge.cpp
)
target_link_libraries(serial_bridge
  ${rclcpp_LIBRARIES}
)

# 创建主节点可执行文件
add_executable(main_node 
  src/main_node.cpp 
  src/imu_publisher.cpp 
  src/odometry_publisher.cpp
)

# 链接依赖
target_link_libraries(main_node
  serial_bridge
  ${rclcpp_LIBRARIES}
  ${sensor_msgs_LIBRARIES}
  ${nav_msgs_LIBRARIES}
  ${geometry_msgs_LIBRARIES}
  ${tf2_ros_LIBRARIES}
  ${tf2_LIBRARIES}
)

# 安装目标
install(TARGETS 
  main_node 
  serial_bridge
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY 
  launch 
  DESTINATION share/${PROJECT_NAME}
)

install(DIRECTORY 
  include/
  DESTINATION include
)

# 添加 ament 导出
ament_export_include_directories(include)
ament_export_libraries(serial_bridge)
ament_package()